/* 
 * File:   Rectangle.cpp
 * Author: mauro
 * 
 * Created on 8 de septiembre de 2014, 19:25
 */

#include "Rectangle.h"
#include "SkinFactory.h"

Rectangle::Rectangle() {
}

Rectangle::Rectangle(ObjFactory *objFactory, bool flagStatic, float posX, float posY, float w, float h, float mass, float rotation) {    
    SBSLog* myLogFile;
    myLogFile->getInstance(MY_LOG_MODE);

    if (w < 0 || h < 0){
        myLogFile->writeInLog(2, "[2] Tamaño del rectangulo invalido (Base o altura negativo)\n");                
    }

    Dot *dot = new Dot(posX,posY,w,h);  
    this->dot = dot;   
    
    Object *object = objFactory->getObject(flagStatic, dot->dotPixelsToWorld() , dot->sizeDotPixelsToWorld(), 0, mass, 4, rotation);
    this->object = object;    

    myLogFile->writeInLog(0, "[0] Se ha creado un rectangulo exitosamente\n");                

}

Rectangle::~Rectangle() {
    delete this->dot;
    delete this->object;
//    printf("Destructor de Rectangle\n");
}
void Rectangle::draw(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
    SBSLog* myLogFile;
    myLogFile->getInstance(MY_LOG_MODE);

    Object *obj = this->object;

    float posX = obj->getBody()->GetPosition().x;
    float posY = obj->getBody()->GetPosition().y;
    this->dot->setPos(posX,posY);  
    
    
    bool ok = obj->getSkin()->makeRectangle(this->dot->dotWorldToPixels(), this->dot->sizeDotWorldToPixels(), this->getAngle(), r, g, b, a);

    if (!ok){
        myLogFile->writeInLog(1, "[1] Ha ocurrido un error mientras se intentaba dibujar el rectangulo\n");                    
    }
}

b2Vec2 Rectangle::getPosition(){
    return this->object->getPosition();
}

float Rectangle::getAngle(){
    return this->object->getAngle();
}

float Rectangle::getAngularVelocity(){
    return this->object->getAngularVelocity();
}

void Rectangle::setAngularVelocity(float velocity){
    this->object->setAngularVelocity(velocity);
}


